package com.winphone.zhgd.web.ls;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.winphone.zhgd.entity.TbLsPost;
import com.winphone.zhgd.entity.TbLsWorker;
import com.winphone.zhgd.service.ITbLsPostService;
import com.winphone.zhgd.service.ITbLsWorkerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.validation.Valid;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zhou
 * @since 2017-08-30
 */
@Controller
@RequestMapping("/tbLsPost")
public class TbLsPostController {

    @Autowired
    private ITbLsPostService ps;

    /**
     * 分页 PAGE
     */
    @GetMapping("/all")
    public Page<TbLsPost> test() {
        return ps.selectPage(new Page<TbLsPost>(0, 12));
    }

    @GetMapping("/allParam")
    public Page<TbLsPost> allPage(TbLsPost tbLsPost,
                                     @RequestParam(value = "current") Integer current,
                                     @RequestParam(value = "size") Integer size){
        Wrapper<TbLsPost> postWrapper = new EntityWrapper<>(tbLsPost);

        Page<TbLsPost> page = ps.selectPage(new Page<>(current,size),postWrapper);
        return  page;
    }

    @RequestMapping(value = "/save")
    public Object saveTbLsPost(@Valid @ModelAttribute("tbLsPost") TbLsPost tbLsPost, BindingResult result){
        if (result.hasErrors()){
            return result.getAllErrors().get(0).getDefaultMessage();
        }
        return ps.insert(tbLsPost);
    }

    @RequestMapping(value = "/delete")
    public boolean deleteTbLsPost(@RequestParam(value = "id") Integer id){
        return ps.deleteById(id);
    }

    @RequestMapping(value = "/get")
    public Object findTbLsPost(@RequestParam(value = "id") Integer id){
        TbLsPost tbLsPost = ps.selectById(id);
        return tbLsPost;
    }

}
